//
//  CityModel.swift
//  XiaoJingMallSwift
//
//  Created by beisheng03 on 2017/8/7.
//  Copyright © 2017年 beisheng. All rights reserved.
//

import UIKit

class CityModel: NSObject {
    
    var province_name = "-999"
    var province_id = "-999"
    
    var city_id = "-999"
    var city_name = "-999"
    var districts = [DistrictModel]()
    
    var level: Int = 2
    var isSelect = false

    
    override init() {
        super.init()
    }
    
    init(dic : [String : AnyObject]) {
        super.init()
        
        setValuesForKeys(dic)
        
    }
    
    
    override func  setValue(_ value: Any?, forKey key: String) {
        
        if key == "districts" {
            
            for item in value as! [[String : AnyObject]] {
                
                districts.append(DistrictModel(dic: item))
                
            }
            
            
            
        } else {
            
            super.setValue(value, forKey: key)
        }

    }
    
    override func setValue(_ value: Any?, forUndefinedKey key: String) {
        
        
    }
    
    
    //在swift中想要打印对象要以下重写属性
    override var description: String{
        let keys = ["city_id","city_name","districts"]
        let dic = dictionaryWithValues(forKeys: keys)
        return "\(dic)"
    }

}
